package com.adinnet.admin.appVersion.controller;


import com.adinnet.admin.appVersion.model.AppVersion;
import com.adinnet.admin.appVersion.model.AppVersionReq;
import com.adinnet.admin.appVersion.service.AppVersionService;
import com.adinnet.core.BaseController;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * app版本管理 前端控制器
 * </p>
 *
 * @author liukp
 * @since 2020-09-23
 */
@Controller
@RequestMapping("appVersion")
public class AppVersionController extends BaseController {

    @Autowired
    private AppVersionService appVersionService;

    @GetMapping
    public String findLevel(Model model){
        return "appVersion/appVersion.html";
    }

    /**
     * app版本管理列表
     * @param req
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public PageResult<AppVersion> list(AppVersionReq req){
        return appVersionService.list(req);
    }

    /**
     * 新增
     * @param appVersion
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public JsonResult add(AppVersion appVersion, HttpServletRequest request) {
        return ok(appVersionService.add(appVersion,request));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("del")
    @ResponseBody
    public JsonResult del(Integer id,HttpServletRequest request) {
        if (ObjectUtils.isEmpty(id)) {
            error("必填参数为空");
        }
        return appVersionService.del(id,request);
    }

    /**
     * 启用
     * @param id
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public JsonResult update(Integer id,HttpServletRequest request) {
        if (ObjectUtils.isEmpty(id)) {
            error("必填参数为空");
        }
        return appVersionService.update(id,request);
    }

}
